package com.brillilab.service.core.experiments.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.brillilab.dao.mapper.experiments.PlateGridGroupMapper;
import com.brillilab.domain.po.experiments.PlateGridGroup;
import com.brillilab.domain.vo.experiments.PlateGridGroupVo;
import com.brillilab.service.core.experiments.IPlateGridGroupService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 多空板分组 服务实现类
 * </p>
 *
 * @author WuMenghao
 * @since 2019-09-05
 */
@Service
@Transactional
public class PlateGridGroupServiceImpl implements IPlateGridGroupService {

    @Resource
    private PlateGridGroupMapper plateGridGroupMapper;

    @Override
    public boolean insertBatch(List<PlateGridGroup> plateGridGroupList) {
        if (CollectionUtils.isNotEmpty(plateGridGroupList)) {
            return plateGridGroupMapper.insertBatch(plateGridGroupList) == plateGridGroupList.size();
        }
        return true;
    }

    @Override
    public List<PlateGridGroup> selectList(List<Long> gridIds) {
        if (CollectionUtils.isNotEmpty(gridIds)) {
            return plateGridGroupMapper.selectList(new LambdaQueryWrapper<PlateGridGroup>().in(PlateGridGroup::getPlateGridId, gridIds));
        }
        return new ArrayList<>();
    }

    @Override
    public List<Long> selectPlateGridIdList(Long plateId) {
        return plateGridGroupMapper.selectPlateGridIdList(plateId);
    }

    @Override
    public boolean deleteBatchById(List<Long> plateGridGroupId) {
        if (CollectionUtils.isNotEmpty(plateGridGroupId)) {
            return plateGridGroupMapper.deleteBatchIds(plateGridGroupId) == plateGridGroupId.size();
        }
        return true;
    }

    @Override
    public boolean deleteBatchByExperimentGroupId(List<Long> experimentGroupId) {
        if (CollectionUtils.isNotEmpty(experimentGroupId)) {
            return plateGridGroupMapper.deleteBatchByExperimentGroupId(experimentGroupId);
        }
        return true;
    }

    @Override
    public int selectCountOnePlate(Long plateId) {
        return plateGridGroupMapper.selectCount(
                new LambdaQueryWrapper<PlateGridGroup>()
                        .eq(PlateGridGroup::getPlateId,plateId));
    }

    @Override
    public boolean deleteByPlateId(Long plateId) {
        return plateGridGroupMapper.delete(
                new LambdaQueryWrapper<PlateGridGroup>()
                        .eq(PlateGridGroup::getPlateId,plateId)) >= 0;
    }

    @Override
    public List<PlateGridGroupVo> selectVoList(List<Long> gridIds) {
        if(CollectionUtils.isNotEmpty(gridIds)){
            return plateGridGroupMapper.selectVoList(gridIds);
        }
        return new ArrayList<>(0);
    }

    @Override
    public boolean deleteByGridIds(List<Long> gridIdList) {
        if(CollectionUtils.isNotEmpty(gridIdList)){
            return plateGridGroupMapper.delete(
                    new LambdaQueryWrapper<PlateGridGroup>()
                            .in(PlateGridGroup::getPlateGridId,gridIdList))>=0;
        }
        return true;
    }

    @Override
    public List<PlateGridGroup> selectListByIds(List<Long> plateGridGroupId) {
        if(CollectionUtils.isNotEmpty(plateGridGroupId)){
            return plateGridGroupMapper.selectList(
                    new LambdaQueryWrapper<PlateGridGroup>()
                            .in(PlateGridGroup::getId,plateGridGroupId));
        }
        return new ArrayList<>(0);
    }
}
